import type { Secret } from "@/views/domain/kubeHud/api/k8s/types";
import { ref } from "vue";
import { useK8SApi } from "@/views/domain/kubeHud/api/k8s/k8s";

const { secretRepo } = useK8SApi();
const dialogVisible = ref(false);

//
const editModel = ref<Secret>();

const initData = (model?: Secret) => {
  editModel.value = model ?? {
    kind: "Secret",
    metadata: {
      labels: {},
      annotations: {}
    },
    data: {}
  };
};

const openEditor = (model?: Secret) => {
  dialogVisible.value = true;
  initData(model);
};

const closeEditor = () => {
  dialogVisible.value = false;
  editModel.value = undefined;
};

const submitCreateForm = async () => {
  console.log(editModel.value);
  secretRepo.createSecret(editModel.value!);
};

export const useCreateSecret = () => {
  return {
    dialogVisible,
    editModel,
    openEditor,
    closeEditor,
    submitCreateForm,
    initData
  };
};
